




Java Abstract Class and Interface






1 






Java Abstract Class and Interface




  Please wait while the activity loads. If this activity does not load, try refreshing your browser. Also, this page requires javascript. Please visit using a browser with javascript enabled.  

  If loading fails, click here to try again  




Question 1Which of the following is FALSE about abstract classes in JavaAIf we derive an abstract class and do not implement all the abstract methods, then the derived class should also be marked as abstract using 'abstract' keywordBAbstract classes can have constructorsCA class can be made abstract without any abstract methodDA class can inherit from multiple abstract classes.Java Abstract Class and Interface    Discuss itQuestion 2Which of the following is true about interfaces in java. 



1) An interface can contain following type of members.

....public, static, final fields (i.e., constants) 

....default and static methods with bodies



2) An instance of interface can be created.



3) A class can implement multiple interfaces.



4) Many classes can implement the same interface.
A1, 3 and 4B1, 2 and 4C2, 3 and 4D1, 2, 3 and 4Java Abstract Class and Interface    Discuss itQuestion 3Predict the output of the following program.



abstract class demo

{

    public int a;

    demo()

    {

        a = 10;

    }



    abstract public void set();

    

    abstract final public void get();



}



class Test extends demo

{



    public void set(int a)

    {

        this.a = a;

    }



    final public void get()

    {

        System.out.println("a = " + a);

    }



    public static void main(String[] args)

    {

        Test obj = new Test();

        obj.set(20);

        obj.get();

    }

}

 

Aa = 10Ba = 20CCompilation errorJava Abstract Class and Interface    Discuss itQuestion 3 Explanation:  Final method can’t be overridden. Thus, an abstract function can’t be final.Question 4Type IV JDBC driver is a driver

Awhich is written in C++Bwhich requires an intermediate layerCwhich communicates through Java socketsDwhich translates JDBC function calls into API not native to DBMSJava Abstract Class and Interface    ISRO CS 2017    Discuss itQuestion 4 Explanation:  JDBC type 4 driver,works directly by connecting to the database server  through socket connections and converts JDBC calls to vendor-specific database protocols.These drivers don't require any intermediate layer.

So, option (C) is correct.Question 5Which of the following statement(s) with regard to an abstract class in JAVA is/are TRUE ?

I. An abstract class is one that is not used to create objects.

II. An abstract class is designed only to act as a base class to be inherited by other classes.AOnly IBOnly IICNeither I nor IIDBoth I and IIJava Abstract Class and Interface    UGC NET CS 2017 Jan - III    Discuss itQuestion 5 Explanation:  

Abstract data class is not used to create objects in Java and it is designed only to act as a base class to be inherited by other classes.

Both Statement are correct.

For more information Refer:Abstract Classes in Java

Option (D) is correct.

Question 6Which of the following is used to make an Abstract class? AMaking atleast one member function as pure virtual function BMaking atleast one member function as virtual function CDeclaring as Abstract class using virtual keyword DDeclaring as Abstract class using  static keyword Java Abstract Class and Interface    UGC NET CS 2015 Dec – III    Discuss itQuestion 6 Explanation:  Making atleast one member function as pure virtual function is the method to make abstract class.

For more information on Abstract Class Refer:Pure Virtual Functions and Abstract Classes in C++

Option (A) is correct.Question 7We can make a class abstract byADeclaring it abstract using the virtual keywordBMaking at least one member function as virtual functionCMaking at least one member function as pure virtual functionDMaking all member function constJava Abstract Class and Interface    ISRO CS 2008    Discuss itQuestion 7 Explanation:  An abstract class is a class that is designed to be specifically used as a base class. An abstract class contains at least one pure virtual function. A pure virtual function can be declared by using a pure specifier ( = 0 ) in the declaration of a virtual member function in the class declaration.



Option (C) is correct. 






  There are 7 questions to complete.  



1 




  

    You have completed     

    questions     

    question     

    Your accuracy is     

    Correct     

    Wrong     

    Partial-Credit     

    You have not finished your quiz. If you leave this page, your progress will be lost.     

    Correct Answer     

    You Selected     

    Not Attempted     

    Final Score on Quiz     

    Attempted Questions Correct     

    Attempted Questions Wrong     

    Questions Not Attempted     

    Total Questions on Quiz     

    Question Details     

    Results     

    Date     

    Score     

    Hint    
Time allowed
minutes
seconds
Time used
Answer Choice(s) Selected
Question Text



























    Need more practice!    



    Keep trying!    



    Not bad!    



    Good work!    



    Perfect!    




















